﻿using System;
using System.Collections.Generic;

namespace LibraryApi
{
    [Serializable]
    public class Book : IComparable
    {
        public Author Author { get; set; }
        public string Title { get; set; }
        public string ISBN { get; set; }
        public DateTime? TakenAt { get; set; }

        public override string ToString()
        {
            if (Author == null)
                throw new ArgumentNullException("Author");

            return string.Format("{0} by {1}", Title, Author.Name);
        }

        public int CompareTo(object obj)
        {
            if(obj == null)
                throw new ArgumentNullException("obj");

            var book = obj as Book;
            if (book == null)
                throw new ArgumentNullException("obj");	
			
			if(this.ISBN == null || book.ISBN == null)
                throw new ArgumentNullException("ISBN");
            return this.ISBN.CompareTo(book.ISBN);
		}
    }
}
